<?php


namespace App\Trip\Crypt;


use App\Models\Common\Channel\Channel;
use App\Models\Common\Channel\Repositories\ChannelRepository;
use function request;

class AppKey
{

    public static function getAppKeyByHeader(): bool|string
    {
        $header_app_key = request()->header('App-Key');
        if (!$header_app_key) {
            return false;
        }
        return self::decrypt($header_app_key);
    }

    /**
     * @param string $input
     *
     * @return bool|string
     */
    public static function decrypt(string $input): bool|string
    {
        $aes = new Aes();
        return $aes->decrypt($input);
    }

    public static function isAppValid(string $appid): bool
    {
        $channelRepo = new ChannelRepository(new Channel());
        return (bool)$channelRepo->findChannelByAppId($appid);
    }
}